
/*========================================================================================
 *                                                                                      *
 *               Copyright(c) 2013-2014, Cha SangWoo, All rights reserved.              *
 *                                                                                      *
 * This file is part of ChaOS.                                                          *
 *                                                                                      *
 * Permission to use, copy, modify, and distribute this software in source and binary   *
 * forms and its documentation for any purpose and without fee is hereby granted,       *
 * provided that the above copyright notice appear in all copies and that both that     *
 * copyright notice and this permission notice appear in supporting documentation.      *
 *                                                                                      *
 * THIS SOFTWARE IS PROVIDED BY THE CHA SANGWOO AND CONTRIBUTORS "AS IS" AND ANY        *
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED            *
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.   *
 * IN NO EVENT SHALL CHA SANGWOO OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,    *
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT         *
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,          *
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF            *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE      *
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,                    *
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                                   *
 *                                                                                      *
========================================================================================*/

#ifndef __CO_LOG_H__
#define __CO_LOG_H__

//#include "co_port.h"
#include "co_types.h"

#ifdef __cplusplus
    extern "C" {
    namespace ChaOS {
#endif

//////////////////////////////////////  < BEGIN >  ///////////////////////////////////////

#ifndef DO_NOTHING
#define DO_NOTHING       do{ }while(0)
#endif

/*======================================================================================*/
/*
    ASSERT MACRO
*/
/*======================================================================================*/
#if (FLAG_USE_ASSERT_MACRO == CO_ENABLE)
    #define CO_ASSERT(EXP)                                                               \
    {                                                                                    \
        if(!(EXP))                                                                       \
        {                                                                                \
            _port_log_printf("ASSERT", "%s %s %s %s %s\n",                               \
                                (CHAR*)#EXP, (CHAR*)"", (CHAR*)__CO_FUNC__,              \
                                (CHAR*)__CO_LINE__, (CHAR*)__CO_FILE__);                 \
                                                                                         \
            while(1);                                                                    \
        }                                                                                \
    }

    #define CO_ASSERT_MSG(EXP, MSG)                                                      \
    {                                                                                    \
        if(!(EXP))                                                                       \
        {                                                                                \
            _port_log_printf("ASSERT", "%s %s %s %s %s\n",                               \
                                (CHAR*)#EXP, (CHAR*)MSG, (CHAR*)__CO_FUNC__,             \
                                (CHAR*)__CO_LINE__, (CHAR*)__CO_FILE__);                 \
                                                                                         \
            while(1);                                                                    \
        }                                                                                \
    }

#else
    #define CO_ASSERT(EXP)               DO_NOTHING
    #define CO_ASSERT_MSG(EXP, MSG)      DO_NOTHING

#endif


/*======================================================================================*/
/*
    LOG MACRO
*/
/*======================================================================================*/
#if (FLAG_USE_LOG_MACRO == CO_ENABLE)

#define LOGI(...)       _port_log_printf("INFO ", __VA_ARGS__)
#define LOGE(...)       _port_log_printf("ERROR", __VA_ARGS__)

#ifdef CO_DEBUG_MODE
    #define LOGD(...)   _port_log_printf("DEBUG", __VA_ARGS__)

#else
    #define LOGD(...)   DO_NOTHING

#endif

    extern UINT _port_log_printf(CHAR *pclass, const CHAR *pformat, ...);

#elif (MCU_FAMILY != MAXQ30)
    #define LOGI(...)   DO_NOTHING
    #define LOGE(...)   DO_NOTHING
    #define LOGD(...)   DO_NOTHING

#endif


//////////////////////////////////////  <  END  >  ///////////////////////////////////////

#ifdef __cplusplus
    } /* namespace ChaOS */
    } /* extern "C" */
#endif

#endif //__CO_LOG_H__

